import Toastify from 'toastify-js';
import "toastify-js/src/toastify.css";

export default function showMessage(message,state='error',callback_func){
    let background_color;
    if (state === 'error'){
        background_color = 'linear-gradient(to right, #ff5f6d, #ffc371)'
    } else {
        background_color = 'linear-gradient(to right, #00b09b, #96c93d)'
    }
    Toastify({
          text: message,
          duration: 3000,
          close: true,
          gravity: "top", // 上下 - top 或 bottom
          position: "center", // 左右 - left、center 或 right
          stopOnFocus: true, // 鼠标悬停时防止关闭
          style: {
            background: background_color,
          },
          callback:function (){
              if (!callback_func) return;
              if (callback_func){
                  callback_func()
              }
          },
          onClick: function(){
              alert('debug onclick')
          } // 点击后的回调
        }).showToast();
}